<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
ul{
    list-style: none;
    width: 500px;
    height: 500px;
    margin: auto;
    background-color: rosybrown;
    border: 1px solid red;
}
li{
 margin: 0 0 10px 4px;
    width: 120px;
    height: 240px;
    float: left;
   background-color: rgba(0, 0, 0, 0.3);
}
    </style>
</head>
<body>
    <ul>
        <li>1</li>
        <li>2</li>
        <li>3</li>
        <li>4</li>
        <li>5</li>
        <li>6</li>
        <li>7</li>
        <li>8</li>
    </ul>
</body>
</html>
<script>
let arr=document.getElementsByTagName("li")
console.log(arr);
for (let i=0;i<arr.length;i++){
arr[i].onmouseenter=function(){
    this.style.backgroundColor='red'

  
}
arr[i].onmouseout=function(){
    this.style.backgroundColor='rgba(0, 0, 0, 0.3)';
}
}
</script>